package com.moyun.finance.controller;

import com.moyun.finance.entity.*;
import com.moyun.finance.service.OrgRoleUserMidService;
import com.moyun.finance.service.OrgRoleUserMidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/org/roleUserMid")
public class OrgRoleUserMidController {
    @Autowired
    OrgRoleUserMidService orumsv;

    //批量新增角色下用户
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody List<OrgRoleUserMid> orums){
        Response res = orumsv.save(orums);
        return res;
    }

//    @RequestMapping("/update")
//    public @ResponseBody Response update(@RequestBody List<OrgRoleUserMid> orums){
//        Response res = orumsv.update(orums);
//        return res;
//    }

    //从角色中删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody OrgRoleUserMid orum){
        Response res = orumsv.delete(orum);
        return res;
    }

    //根据角色查用户
    @RequestMapping("/findAllUserByRole")
    public @ResponseBody Response findAllUserByRole(String roleId){
        List<OrgUser> users = orumsv.findAllUserByRole(roleId);
        return new Response("",users,true);
    }

    //根据用户id查角色
    @RequestMapping("/findUserRoleByUser")
    public @ResponseBody Response findUserRoleByUser(String userId){
        List<OrgRole> roles = orumsv.findUserRoleByUser(userId);
        return new Response("",roles,true);
    }
}
